
package.path = "./lua/?.lua;" .. package.path
local cjson = require "cjson"
local grafana = require "grafana_m"
local http2tcp = require "http2tcp"
local resp = {
	msg = "ok",
	code = 0 
}

local function readFile(fileName)
    local f = assert(io.open(fileName,'r'))
    local content = f:read('*all')
    f:close()
    return content
end

local payload = readFile("bak.lua")

http2tcp:new("127.0.0.1", 9877)

grafana:new()
local sql = string.format([[
        insert into wrk_task_tab set 
        status='running',
        creator='system',
        start_time=Now(),
        ctime=Now()
    ]])

local res = grafana:db_query(sql)
local taskid = res.insert_id
http2tcp:send({taskid=taskid, is_force=0, name="", command="start", payload=payload})
local data = http2tcp:receive()
data.taskid = taskid
resp.data = data
ngx.say(cjson.encode(resp))

